package com.farsunset.ichat.cim.handler;

import org.apache.log4j.Logger;

import com.farsunset.cim.nio.constant.CIMConstant;
import com.farsunset.cim.nio.handler.CIMRequestHandler;
import com.farsunset.cim.nio.mutual.ReplyBody;
import com.farsunset.cim.nio.mutual.SentBody;
import com.farsunset.cim.nio.session.CIMSession;
import com.kuaigou.cim.util.AESEncodeUtil;

/**
 * 
 * 消息确认
 */
public class MessageConfirmHandler implements CIMRequestHandler {
	
	protected final Logger logger = Logger.getLogger(MessageConfirmHandler.class);

	public ReplyBody process(CIMSession session, SentBody message) {
		ReplyBody reply = new ReplyBody();
		try { 
			reply.setKey(CIMConstant.RequestKey.CLIENT_MESSAGE_CONFIRM);
			String account = message.get("account");
			String verificationCode = message.get("verificationCode");		
			if(verificationCode == null ||  !account.equals(AESEncodeUtil.decrypt(verificationCode,AESEncodeUtil.key))){
				reply.setCode(CIMConstant.ReturnCode.CODE_403);
				return reply;
			}	
			
			System.out.println("msessgeconform:" + message.get("mid") + ":" + message.get("status"));
			reply.setCode(CIMConstant.ReturnCode.CODE_200);			
		} catch (Exception e) {
			reply.setCode(CIMConstant.ReturnCode.CODE_500);
		}
		return reply;
	}	
	
}
